package com.example.gulimall.order.controller;

import com.example.gulimall.order.entity.OrderEntity;
import com.example.gulimall.order.entity.OrderReturnApplyEntity;
import com.example.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class RabbiitController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("/sendMq")
    public String sendMq(@RequestParam(value = "num",defaultValue = "10") Integer num){
        for (int i=0;i<num;i++){
           // if (i%2==0){
                OrderReturnReasonEntity orderReturnReasonEntity = new OrderReturnReasonEntity();
                orderReturnReasonEntity.setId(1l);
                orderReturnReasonEntity.setCreateTime(new Date());
                orderReturnReasonEntity.setName("哈哈"+i);
                //如果发送的消息是一个对象会使用序列化工具写出去，并且默认是使用jdk的序列化
                //可以修改成json序列化
                String msg="hello word";
                rabbitTemplate.convertAndSend("hello-java-exchange","hello.java",orderReturnReasonEntity,new CorrelationData(UUID.randomUUID().toString()));
                System.out.println("消息发送成功，"+i);
         //   }else {
//                OrderEntity orderEntity = new OrderEntity();
//                orderEntity.setId(1l);
//                orderEntity.setCreateTime(new Date());
//                orderEntity.setOrderSn("aaa");
//                //如果发送的消息是一个对象会使用序列化工具写出去，并且默认是使用jdk的序列化
//                //可以修改成json序列化
//                String msg="hello word";
//                // 最后一个参数消息的唯一id
//                rabbitTemplate.convertAndSend("hello-java-exchange","hello.java",orderEntity,new CorrelationData(UUID.randomUUID().toString()));
//                System.out.println("消息发送成功，"+i);
            }

        //}
        return "ok";
    }
}
